package com.wxtl.util;

import java.io.IOException;
import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import com.wxtl.entity.UpgradePack;
import com.wxtl.ws.vo.UPResult;

/**
 * XML<-->JavaBean 工具
 * @author hc24
 *
 */
public class JaxbUtil {
	
	public static String marshal(Object obj,Class<?> ... clazz){
		JAXBContext context;
		StringWriter sw = new StringWriter();
		try{
			context = JAXBContext.newInstance(clazz);
			Marshaller marshaller = context.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_ENCODING, "utf-8");
			
			marshaller.marshal(obj, sw);
		}catch(Exception e){
			System.out.println(e);
		}finally{
			try {
				sw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return sw.toString();
	}
	
}
